import Page
from Page import Yomi
from Base.Base import Base
from selenium.webdriver.common.by import By


class YomiOnlineRadioPage(Base):
    """
    语音训练导航在线电台

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.radio_home_btn = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("ivHome"))

        # 左侧的返回键
        self.radio_back_btn = (By.XPATH, Yomi.RESOURCE_ID_Xting.format('ivBack'))

        # 本地电台标题
        self.radio_local_title_text = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("btn_native"))

        # 在线电台标题
        self.radio_online_title_text = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("btn_online"))

        # 语音搜索
        self.radio_voice_btn = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("bt_voice"))

        # 节目输入
        self.radio_program_input = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("et_music"))

        # 立即搜索
        self.radio_now_search_btn = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("btn_search"))

        # 搜索历史标题
        self.radio_search_history_title_text = (By.XPATH, Yomi.RESOURCE_ID_Xting.format("tv_search_result_title"))

        # 搜索历史
        self.radio_search_history_text = (By.XPATH, Yomi.search_result_text.format(""))

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.radio_back_btn)

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.radio_home_btn)

    def get_online_title(self):
        """
        获取在线电台标题

        :return:获取元素
        """
        return self.find_element_o(self.radio_online_title_text)

    def get_local_title(self):
        """
        获取本地电台标题

        :return:获取元素
        """
        return self.find_element_o(self.radio_local_title_text)

    def click_local_title(self):
        """
        点击本地电台

        :return:None
        """
        self.click_element(self.radio_local_title_text)

    def click_online_title(self):
        """
        点击在线电台

        :return:None
        """
        self.click_element(self.radio_online_title_text)

    def click_voice(self):
        """
        点击语音搜索按钮

        :return:None
        """
        self.click_element(self.radio_voice_btn)

    def input_program(self, index):
        """
        节目输入

        index 为输入的节目
        :return:None
        """
        self.input_text(self.radio_program_input, index)

    def get_program(self):
        """
        获取节目输入内容

        :return:None
        """
        return self.find_element_o(self.radio_program_input)

    def click_now_search(self):
        """
        点击立即搜索

        :return:None
        """
        self.click_element(self.radio_now_search_btn)

    def get_search_history_title(self):
        """
        获取搜索历史标题

        :return:获取元素
        """
        return self.find_element_o(self.radio_search_history_title_text)

    def get_search_history(self, index=1):
        """
        获取搜索结果

        :return:获取元素
        """
        self.radio_search_history_text = (By.XPATH, Yomi.search_result_text.format(index))
        return self.find_element_o(self.radio_search_history_text)

    def swipe_radio_online_list(self):
        """
        滑动城市列表

        :return:None
        """
        self.swipe_o(location=(952, 952, 438, 640), direction='up')

    def is_display_yomi_online_radio(self):
        """
        查看是否进入语音训练在线电台
        :return:
        """
        return self.is_display(self.radio_voice_btn)
